package com.aatrox.bhsypro.controller;

import com.aatrox.bhsypro.entity.BUser;
import com.aatrox.bhsypro.entity.BhSyHr;
import com.aatrox.bhsypro.service.BhSyHrService;
import com.aatrox.bhsypro.service.UserTalkService;
import com.aatrox.bhsypro.util.CookieUtil;
import com.aatrox.bhsypro.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;

@Controller
public class ZhuanLangController {

    @Autowired
    UserTalkService userTalkService;
    @Autowired
    RedisTemplate<String,Object> redisTemplate;
    @Autowired
    BhSyHrService bshs;
    @RequestMapping("/scolumn/{uid}/{sid}/{sName}")
    public String scolumn(@PathVariable("uid") int uid , @PathVariable("sid") int sid, @PathVariable("sName") String sName, ModelMap mm, HttpServletRequest request, HttpSession session){
        String ticket = CookieUtil.getCookieValue(request,"userTicket");
        BUser bUser = (BUser) redisTemplate.opsForValue().get("user:"+ticket+"uid:"+(session.getAttribute("buserId")));
        BhSyHr bsh = new BhSyHr(bUser.getUid(),sid,2);
        bshs.insertNewHr(bsh);
        mm.put("sUid",uid);
        mm.put("sName",sName);
        mm.put("sid",sid);
        List list=userTalkService.selbyid(sid,3);
        mm.put("list",list);
        return "realuser/scolumn";
    }
}
